/**
 * Copyright (C) 2011, mordredd666 [_at_] gmail.com
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package de.mordred;

import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import de.mordred.gui.FixedPanel;
import de.mordred.gui.SelectionScreen;
import de.mordred.gui.StartScreen;
import de.mordred.util.VersionCheck;

public class Main
{

	private static JFrame _hauptfenster;
	private static ArrayList<Frage> _fragen;
	private static FixedPanel _panel;

	private static ArrayList<String> _fächer;
	private static ArrayList<Integer> _examinaJahre;

	public static void main(String[] args)
	{

		_hauptfenster = new JFrame("jPhysikum");
		_hauptfenster.setIconImage(Loader.getImageIcon("Doctor.png").getImage());
		_hauptfenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		_panel = new StartScreen();

		_hauptfenster.add(_panel);
		_hauptfenster.pack();
		_hauptfenster.setLocationRelativeTo(null);
		_hauptfenster.setVisible(true);

		_fragen = Datenbankeinleser.getFragen();

		_examinaJahre = Datenbankeinleser.getExaminaJahre();

		_fächer = Datenbankeinleser.getFächer();

		VersionCheck.checkUpdate();

		try
		{
			Thread.sleep(1000);
		}
		catch (InterruptedException e)
		{
		}

		setNextPanel(new SelectionScreen());

	}

	public static JFrame getHauptfenster()
	{
		return _hauptfenster;
	}

	public static ArrayList<Frage> getFragen()
	{
		return _fragen;
	}

	public static ArrayList<String> getFächer()
	{
		return _fächer;
	}

	public static ArrayList<String> getThemenFürFach(String fach)
	{
		return Datenbankeinleser.getThemenFürFach(fach);
	}

	public static ArrayList<Integer> getExaminaJahre()
	{
		return _examinaJahre;
	}

	public static void setNextPanel(final FixedPanel newpanel)
	{
		SwingUtilities.invokeLater(new Runnable()
		{

			@Override
			public void run()
			{
				_hauptfenster.remove(_panel);
				_panel = newpanel;
				_hauptfenster.add(_panel);
				_hauptfenster.repaint();
				_hauptfenster.invalidate();
				_hauptfenster.validate();
				_hauptfenster.pack();
			}
		});
	}
}
